package com.layui.ad.controller;

import com.layui.ad.query.CommunityQuery;
import com.layui.ad.service.CommunityService;
import com.layui.ad.utils.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/community")
public class CommunityController extends BaseController {

    @Resource
    private CommunityService communityService;

    @RequestMapping("/index")
    @ResponseBody
    public JsonResult index(CommunityQuery communityQuery){
        //参数表时是通过url中传递参数
        return communityService.getRecordList(communityQuery);
    }

    @RequestMapping("/page")
    @ResponseBody
    public JsonResult page(CommunityQuery communityQuery){
//        JsonResult obj = communityService.getAllByPage(communityQuery);
        Map<String,Object> map = communityService.getAllByPageMap(communityQuery);
        Long count = Long.valueOf(String.valueOf(map.get("count")));
        return JsonResult.ok("",map.get("data"),count);

    }
}
